package com.hua.Thread;

import java.util.concurrent.CountDownLatch;

/**
 * @author: _hua
 * @created: 2019/3/3.
 * @updater:
 * @description:
 */
public class CountDownLatchDemo {

    public static void main(String args[]){
        CountDownLatch countDownLatch = new CountDownLatch(1);
        new Thread(new Runnable() {

            @Override
            public void run() {
                try {
                    long startTime = System.currentTimeMillis();
                    countDownLatch.await(); //调用countDownLatch.await()的线程被阻塞
                    System.out.println("currentThread============"+Thread.currentThread().getName());
                    long endTime = System.currentTimeMillis();
                    System.out.println("awaitTime : " + (endTime - startTime) / 1000 + "seconds");
                } catch (InterruptedException e) {}

            }
        }).start();
        try {
            Thread.sleep(5000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("currentThread============"+Thread.currentThread().getName());
        countDownLatch.countDown();//调用countDownLatch.countDown()被阻塞的线程可以继续运行
    }



}
